package com.yxq.mdt.app.modules.spikedetail.presenter;


import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.market.bean.MallGoodsBean;
import com.yxq.mdt.app.modules.spikedetail.bean.GoodsCommentBean;
import com.yxq.mdt.app.modules.spikedetail.bean.SpikeGoodsDetailBean;
import com.yxq.mdt.app.modules.spikedetail.model.SpikeGoodsModel;
import com.yxq.mdt.app.net.ApiModel;

public class SpikeGoodsPresenter extends BasePresenter<ISpikeGoodsContract.View, SpikeGoodsModel> implements ISpikeGoodsContract.Presenter {

    public SpikeGoodsPresenter(ISpikeGoodsContract.View view, SpikeGoodsModel model) {
        super(view, model);
    }

    @Override
    public void getGoods(String id) {

        mBaseModel.getGoods(id, new ApiModel.CommonCallback<SpikeGoodsDetailBean>() {
            @Override
            public void onSuccess(SpikeGoodsDetailBean goodsDetailBean) {
                mRootView.onLoadSuccess(goodsDetailBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void getGoodsRecommend(String goods_id) {

        mBaseModel.goodsRecommend(goods_id, new ApiModel.CommonCallback<MallGoodsBean>() {
            @Override
            public void onSuccess(MallGoodsBean mallGoodsBean) {
                mRootView.onLoadRecommendSuccess(mallGoodsBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadRecommendFailed(errMsg);
            }
        });
    }

    public void favoriteAdd(String goods_id) {

        mBaseModel.favoriteAdd(goods_id, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String mallGoodsBean) {
                mRootView.onAddSuccess(mallGoodsBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onAddFailed(errMsg);
            }
        });
    }

    public void favoriteRemove(String goods_id) {

        mBaseModel.favoriteRemove(goods_id, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String mallGoodsBean) {
                mRootView.onRemoveSuccess(mallGoodsBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onRemoveFailed(errMsg);
            }
        });
    }

    public void getCommentList(String goods_id, int page) {

        mBaseModel.getCommentList(goods_id, page, new ApiModel.CommonCallback<GoodsCommentBean>() {
            @Override
            public void onSuccess(GoodsCommentBean goodsCommentBean) {
                mRootView.onLoadCommentSuccess(goodsCommentBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadCommentFailed(errMsg);
            }
        });
    }

    public void addCart(String goods_id, int num, String attr) {

        mBaseModel.addCart(goods_id, num, attr, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String goodsCommentBean) {
                mRootView.onAddCartSuccess(goodsCommentBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadCommentFailed(errMsg);
            }
        });
    }
}
